package ten;


import static util.Print.print;

/**
 * Created by ab on 2016/11/4.
 */
interface Selector {
    boolean end();

    Object current();

    void next();
}

public class lesson3 {
    private Object[] items;
    private int next = 0;

    public lesson3(int size) {
        items = new Object[size];
    }

    public void add(Object x) {
        if (next < items.length)
            items[next++] = x;
    }

    private class SequenceSelector implements Selector {
        private int i = 0;

        @Override
        public boolean end() {
            return i == items.length;
        }

        @Override
        public Object current() {
            return items[i];
        }

        @Override
        public void next() {
            if (i < items.length) i++;
        }
    }

    public Selector selector() {
        return new SequenceSelector();
    }

    class SomeString{
        private String value;
        SomeString(String s){
            value=s;
        }
        public String toString(){
            return value.toString();
        }
    }

    public SomeString getString(String s){
        return new SomeString(s);
    }

    public static void main(String[] args) {
        lesson3 l = new lesson3(10);
        for (int i = 0; i < 10; i++)
            l.add(Integer.toString(i));
        Selector selector = l.selector();
        while (!selector.end()) {
            print(selector.current() + " ");
            selector.next();
        }
    }
}
